﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Business
{
    /// <summary>
    /// View by Nhat
    /// </summary>
    public partial class myMasterPlan
    {
        public static List<myMasterPlan> getByProjectID(long ID)
        {
            DataClassesDataContext db = null;
            try
            {
                db = new DataClassesDataContext(Common.Global.GetConnectionInfo().ConnectionStringSQL);
                var query = from dt in db.myMasterPlans
                            where dt.ID == ID
                            select dt;
                var l = query.ToList();
                foreach (var item in l)
                {
                    var schedule = db.TeamSchedules.Where(p => p.ProjectTeam == item.ProjectTeamID);
         
                    item.schedule_list = schedule.ToList() ;

                    foreach (var i in item.schedule_list)
                    {
                        i.WorkTypeName = db.CodeDetails.Where(p => p.CMCode == "Schedule" && p.NumberValue == i.WorkType).FirstOrDefault().StandardName;
                    }
                }
                return l;
            }
            catch
            {
                return null;
            }
            finally
            {
                db = null;
            }
        }
    }

    public partial class myMasterPlan
    {
        public List<TeamSchedule> schedule_list { get; set; }
    }

    public partial class TeamSchedule
    {
        public string WorkTypeName { get; set; }
    }
}
